package com.freshcity.component.guide
{
	import com.freshcity.graphics.GuideWin;
	import com.freshcity.graphics.LineBoxTipWin;
	import com.freshcity.manager.EffectManager;
	import com.freshcity.manager.support.MaskInfo;
	import com.freshcity.utils.StringUtil;
	import com.greensock.TweenLite;
	import com.pblabs.debug.Logger;

	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class LineBoxTips extends Sprite
	{
		public var manger:GuideTipsManager;
		private var _tips:LineBoxTipWin;
		private var _txt:String;
		private var _hitHeight:int;
		private var _dir:int;
		private var _lineBox:LineBox;

		private var _callBack:Function;
		private var _message:String;
		private var _msgNum:int;
		private var _timeOut:int;
		private var _callBackPara:*;
		private var maskSp:Sprite;

		public function LineBoxTips()
		{
			this._hitHeight=25;
			this._tips=new LineBoxTipWin();
		}

		public function updateDir(dir:int):void
		{
			this._dir=dir;
		}

		public function updateTxt(arg1:String):void
		{
			//this._txt.htmlText = StringUtil.addColor(arg1, "#ffffff");
			this._txt=arg1;
		}

		public function updateRect(mask:MaskInfo):void
		{
			this._lineBox=EffectManager.getLineBox(mask.width, mask.height, [16711680, 16776960]);
			if (this._lineBox.parent != this)
			{
				this.addChild(this._lineBox);
				var loc1:*=this._dir;
				switch (loc1)
				{
					case GuideTipsManager.Dir_BL:
					{
						this._tips.gotoAndStop(1);
						this._tips.x=mask.width / 2;
						this._tips.y=0;
						break;
					}
					case GuideTipsManager.Dir_BR:
					{
						this._tips.gotoAndStop(2);
						this._tips.x=0;
						this._tips.y=-mask.height;
						break;
					}
				}
				this.addChild(this._tips);
			}
			_tips.label.text=this._txt;
			addMask(mask);
			//this._lineBox.x = (-arg1) / 2 - 2;
			//this._lineBox.y = -arg2 - 2;
		}

		private function addMask(mask:MaskInfo):void
		{
			//增加遮罩
			maskSp=new Sprite();
			with (maskSp.graphics)
			{
				clear();
				lineStyle(0, 0, 0);
				beginFill(0, 0);
				drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
				switch (mask.shape)
				{
					case MaskInfo.Shape_Cycle:
					{
						drawCircle(mask.x, mask.y, mask.width);
						break;
					}
					case MaskInfo.Shape_Rect:
					{
						drawRect(mask.x, mask.y, mask.width, mask.height);
						break;
					}
				}
				endFill();
			}
			this.parent.addChildAt(maskSp, 0);
		}

		public function updateCallBack(arg1:Function):void
		{
			if (!this._lineBox)
				return;
			this._callBack=arg1;
			if (arg1 == null)
			{
				this.mouseChildren=false;
				this.mouseEnabled=false;
				this._lineBox.removeEventListener(MouseEvent.CLICK, this.onMouseClick);
			}
			else
			{
				this.mouseEnabled=false;
				this.mouseChildren=true;
				this._lineBox.buttonMode=true;
				this._lineBox.mouseEnabled=true;
				this._lineBox.addEventListener(MouseEvent.CLICK, this.onMouseClick);
			}
		}

		private function onMouseClick(arg1:MouseEvent):void
		{
			if (this._callBack != null)
			{
				_callBack.apply(null, _callBackPara);
			}
		}

		public function dispose():void
		{
			this.mouseChildren=false;
			this.mouseEnabled=false;
			//mortal.game.manager.EffectManager.glowFilterUnReg(this._bodySprite);
			EffectManager.disposeLineBox(this._lineBox);
			this._callBack=null;
			if (maskSp && maskSp.parent)
				maskSp.parent.removeChild(maskSp);
			while (this.numChildren > 0)
			{
				this.removeChildAt(0);
			}
		}
	}
}